#!/usr/bin/bash
#
# Init T-One Agent
#

# Get 'admin_urls_token' from the config file
function get_admin_urls_token
{
    typeset config_file=${1?"*** docker_compose.yaml"}
    grep -E 'admin_urls_token:' $config_file | awk -F':' '{print $NF}' | xargs echo
}

config_file=${1?"*** docker_compose.yaml"}
admin_urls_token=$(get_admin_urls_token $config_file)
curl -s "http://127.0.0.1:8081/admin/migrate/?token=${admin_urls_token}"
curl -s "http://127.0.0.1:8081/admin/create_superuser/?token=${admin_urls_token}&username=admin&password=admin123"
curl -s "http://127.0.0.1:8081/admin/import_access_token/?token=${admin_urls_token}"
